﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using NasuTek.Shion.Agent;
using WeifenLuo.WinFormsUI.Docking;

namespace NasuTek.Shion
{
    public partial class Inspector : DockContent
    {
        string Server;
        string Channel;
        bool opening = true;
        public Inspector(string channel, string server, string topic)
        {
            InitializeComponent();
            Server = server;
            Channel = channel;
            label1.Text = channel;
            textBox1.Text = topic;
            Text = "Inspector - " + channel;

            string mode = Form1.ChannelModes[server][channel];

            if (mode.Contains('t')) { t.Checked = true; }
            if (mode.Contains('m')) { m.Checked = true; }
            if (mode.Contains('i')) { i.Checked = true; }
            if (mode.Contains('n')) { n.Checked = true; }
            if (mode.Contains('p')) { p.Checked = true; }
            if (mode.Contains('s')) { s.Checked = true; }

            if ((Form1.Ops[Server][Channel].Contains(Form1.Clients[Server].Nickname) == false) && (Form1.HalfOps[Server][Channel].Contains(Form1.Clients[Server].Nickname) == false))
            {
                t.Enabled = false;
                m.Enabled = false;
                i.Enabled = false;
                n.Enabled = false;
                p.Enabled = false;
                s.Enabled = false;
                button4.Enabled = false;
            }
            opening = false;

        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (modes.Visible == true) { modes.Visible = false; }
            else { modes.Visible = true; }
        }

        private void Inspector_Load(object sender, EventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {

        }

        private void button2_Click_1(object sender, EventArgs e)
        {
            if (textBox1.Visible == true) { textBox1.Visible = false; }
            else { textBox1.Visible = true; }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            Form1.Clients[Server].Ban(label1.Text);
        }

        private void Inspector_FormClosing(object sender, FormClosingEventArgs e)
        {
            
        }

        private void button3_Click_1(object sender, EventArgs e)
        {
            if (panel3.Visible == true) { panel3.Visible = false; }
            else { panel3.Visible = true; }
        }

        private void panel1_Paint(object sender, PaintEventArgs e)
        {

        }

        public void AddBans(List<string> bans)
        {
            listBox1.Items.AddRange(bans.ToArray());
        }

        private void t_CheckedChanged(object sender, EventArgs e)
        {
            if (opening == false)
            {
                if ((Form1.Ops[Server][Channel].Contains(Form1.Clients[Server].Nickname)) || (Form1.HalfOps[Server][Channel].Contains(Form1.Clients[Server].Nickname)))
                {
                    if (t.Checked) { Form1.Clients[Server].RfcMode(Channel, "+t"); }
                    else { Form1.Clients[Server].RfcMode(Channel, "-t"); }
                }
            }
        }

        private void n_CheckedChanged(object sender, EventArgs e)
        {
            if (opening == false)
            {
                if (n.Checked) { Form1.Clients[Server].RfcMode(Channel, "+n"); }
                else { Form1.Clients[Server].RfcMode(Channel, "-n"); }
            }
        }

        private void i_CheckedChanged(object sender, EventArgs e)
        {
            if (opening == false)
            {
                if (i.Checked) { Form1.Clients[Server].RfcMode(Channel, "+i"); }
                else { Form1.Clients[Server].RfcMode(Channel, "-i"); }
            }
        }

        private void m_CheckedChanged(object sender, EventArgs e)
        {
            if (opening == false)
            {
                if (m.Checked) { Form1.Clients[Server].RfcMode(Channel, "+m"); }
                else { Form1.Clients[Server].RfcMode(Channel, "-m"); }
            }
        }

        private void p_CheckedChanged(object sender, EventArgs e)
        {
            if (opening == false)
            {
                if (p.Checked) { Form1.Clients[Server].RfcMode(Channel, "+p"); }
                else { Form1.Clients[Server].RfcMode(Channel, "-p"); }
            }
        }

        private void s_CheckedChanged(object sender, EventArgs e)
        {
            if (opening == false)
            {
                if (s.Checked) { Form1.Clients[Server].RfcMode(Channel, "+s"); }
                else { Form1.Clients[Server].RfcMode(Channel, "-s"); }
            }
        }

        private void button4_Click(object sender, EventArgs e)
        {
            Form1.Clients[Server].Unban(Channel, listBox1.SelectedItem.ToString());
            listBox1.Items.Remove(listBox1.SelectedItem);
        }
    }
}